/**
 * 
 */
package com.youxin.cpcenter.pt.service.login;

import com.youxin.busfoundation.bean.ent.ResponseAccountsBean;
import com.youxin.busfoundation.bean.login.RequestLoginBean;
import com.youxin.busfoundation.common.es.bean.CompanyInfoBean;
import com.youxin.busfoundation.net.WebVisitor;
import com.youxin.cpcenter.pt.bean.ResponseLogin;
import com.youxin.cpcenter.pt.common.PtConfig;
import com.youxin.cpcenter.pt.service.BaseOperation;
import com.youxin.cpcenter.pt.service.PtTask;
import com.youxin.foundation.utils.JsonUtils;

/**
 * @author yingde.cao
 * @date 2017年12月23日
 * @version 1.0
 */
public class LoginPt extends BaseOperation{
	
	public static ResponseLogin postMethod(RequestLoginBean bean,CompanyInfoBean companyInfoBean) {
		String urlSuffix=PtConfig.LOGIN_SURFIX;
		String url = PtConfig.currentURL() + urlSuffix;
		String outJson = WebVisitor.instance().httpPostJsonBody(url, bean);
		ResponseLogin outBean = JsonUtils.stringToFasterxmlObject(outJson, ResponseLogin.class);
		if(outBean.success())
		{
			ResponseAccountsBean accountsBean=outBean.getData();
			PtTask.instanse().setCompanyToken(companyInfoBean.getUid(), accountsBean.getToken());
		}else{
			logger.error(outBean.toString());
		}
		
		long time=outBean.getResponseTime()-bean.getRequestTime();
		saveRequestTimeToRedis(PtConfig.LOGIN_SURFIX, time);
		
		return outBean;
	}
}
